﻿using System;
using System.Collections.Generic;
using System.Text;

namespace _017_字段_属性_索引器_常量_3_
{
    internal class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Student student = new Student();
                student.Age = 20;

                Student student2 = new Student();
                student2.Age=20;

                Student student3 = new Student();
                student3.Age=200;

                int Age = (student.GetAge() + student2.GetAge() + student3.GetAge()) / 3;
                Console.WriteLine(Age);
            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
            }

            Student.Amount = 29;
            Console.WriteLine(Student.Amount);
        }
    }

    class Student
    {

        private int age;

        public int Age
        {
            get
            {
                return this.age;
            }

            set
            {
                if (value >= 0 && value <= 120)
                {
                    this.age = value;
                }
                else
                {
                    throw new Exception("Age value has error");
                }
            }
        }


        private static int amount;
        public static int Amount
        {
            get
            {
                return Student.amount;
            }
            set
            {
                if (value >= 0)
                {
                    amount = value;
                }
                else
                {
                    Console.WriteLine("数量非负值");
                }

            }
        }

        public int GetAge()
        {
            return this.age;
        }

        //public void SetAge(int value)
        //{
        //    if (value >= 0 && value <= 120)
        //    {
        //        this.age = value;
        //    }
        //    else
        //    {
        //        throw new Exception("年龄超过限制");
        //    }
        //}


    }
}
